//
//  DetailGoodShopCommentTableViewCell.m
//  BTRIP
//
//  Created by johnbk on 15/11/14.
//  Copyright © 2015年 johnbk. All rights reserved.
//

#import "DetailGoodShopCommentTableViewCell.h"
#import <SDWebImageManager.h>
#import <UIImageView+WebCache.h>
#import "SuitableHeight.h"
@implementation DetailGoodShopCommentTableViewCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(void)dealloc{
	[_imageViewOfComment_avatar release];
	[_labelOfComment_content release];
	[_labelOfComment_nickname release];
	[_comments release];
	[super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
	self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
	if (self) {
		[self createView];
	}
	return  self;
}
- (void)createView{
	self.imageViewOfComment_avatar = [[UIImageView alloc]init];
	[self.contentView addSubview:self.imageViewOfComment_avatar];
	[self.imageViewOfComment_avatar release];
	
	self.labelOfComment_nickname = [[UILabel alloc]init];
	[self.contentView addSubview:self.labelOfComment_nickname];
	[self.labelOfComment_nickname release];
	
	self.labelOfComment_content = [[UILabel alloc]init];
	[self.contentView addSubview:self.labelOfComment_nickname];
	[self.labelOfComment_nickname release];
	
	self.labelOfComment_content = [[UILabel alloc]init];
	[self.contentView addSubview:self.labelOfComment_content];
	[self.labelOfComment_content release];
}
- (void)layoutSubviews{
	[super layoutSubviews];
	self.imageViewOfComment_avatar.frame = CGRectMake(20, 20, 30, 30);
	self.imageViewOfComment_avatar.layer.cornerRadius = self.imageViewOfComment_avatar.frame.size.width / 2;
	self.labelOfComment_nickname.frame = CGRectMake(self.imageViewOfComment_avatar.frame.origin.x + 20 + self.imageViewOfComment_avatar.frame.size.width, self.imageViewOfComment_avatar.frame.origin.y + 8, 100, 25);
	self.labelOfComment_nickname.font = [UIFont systemFontOfSize:12];
	self.labelOfComment_content.frame = CGRectMake(self.imageViewOfComment_avatar.frame.origin.x, self.imageViewOfComment_avatar.frame.origin.y + 15 + self.imageViewOfComment_avatar.frame.size.height, self.frame.size.width - 40, self.heightOfContent);
	self.labelOfComment_content.font = [UIFont systemFontOfSize:12];
	self.labelOfComment_content.numberOfLines = 0;
	self.labelOfComment_content.lineBreakMode = NSLineBreakByWordWrapping;
	self.labelOfComment_content.textColor = [UIColor darkGrayColor];
	
}
- (void)setComments:(Comments *)comments{
	if (_comments != comments) {
		[_comments release];
		_comments = [comments retain];
		[self layoutSubviews];
		[self.imageViewOfComment_avatar sd_setImageWithURL:[NSURL URLWithString:comments.author.avatar] placeholderImage:[UIImage imageNamed:@"background"]];
		self.labelOfComment_nickname.text = comments.author.nickname;
		self.labelOfComment_content.text = comments.content;
		self.heightOfContent = [SuitableHeight suitableHeight:comments.content andWidth:(self.labelOfComment_content.frame.size.width) andFont:12];
	}
}
+ (DetailGoodShopCommentTableViewCell *)tableView:(UITableView *)tableView{
	static NSString *cellIdentifier = @"DetailGoodShopCommentTableViewCellIdentifier";
	DetailGoodShopCommentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
	if (!cell) {
		cell = [[DetailGoodShopCommentTableViewCell alloc]init];
	}
	return cell;
}
@end
